ShenDoc 30


 

 

Type Declarations

The primitive type is used to annotate any s-expression. The notation is

(type X α)

as in '(type X number)'. This is not in any sense a normal function since the type α is discarded in evaluation (i.e. (type X α) evaluates to the normal form of X. The type declaration is not ignored by the type checker which actually expects the expression to have the type attached to it and will signal an error if this is not so.

The degree to which any implementation of Kλ uses the information provided by this annotation will depend on the platform and the implementation. Shen 11 and later will, if required, automatically generate copious type annotations in Kλ which can be used by Kλ implementors or platform providers of Shen to optimise the resultant code. The command '(optimise +)' enables this feature. The default is '(optimise -)'.

Optimisation of the type declarations in a type checked Shen function F is expected to preserve the I/O features of F only with respect to type secure input. Thus

  (define =n
    {number --> number --> boolean} 
    N N -> true
    _ _ -> false)

may return an error on non-numeric inputs when optimised.

Acknowledgements

History
Basic Types in Shen and Kλ
The Primitive Functions of Kλ
The Syntax of Kλ
Notes on the Implementation of Kλ
Boolean Operators
The Syntax of Symbols
The Semantics of Symbols in Shen and Kλ
Packages
Prolog
Shen-YACC
Strings
Strings and Pattern Matching
Lists
Streams
Character Streams and Byte Streams
Bytes and Unicode
Reader Macros
Vectors
Standard Vectors and Pattern Matching
Non-standard Vectors and Tuples
Equality
I/O
Generic Functions
Eval
Type Declarations
External Global Variables
Property Lists and Hashing
Error Handling
Numbers
Floats and Integers
The Timer
Comments
Special Forms

Built by Shen Technology (c) Mark Tarver, September 2021